#include<iostream>
#include<vector>

using namespace std;



int maxTurbulenceSize(vector<int>& nums) {
    int n = nums.size();

    vector<int> f(n, 1);
    auto g = f;
    int ret = 1;
    for (int i = 1; i < n; i++)
    {
        if (nums[i] > nums[i - 1]) f[i] = g[i - 1] + 1;
        if (nums[i] < nums[i - 1]) g[i] = f[i - 1] + 1;
        //ret = max(f[i],g[i]);
        ret = max(ret, max(f[i], g[i]));
    }
    return ret;
}


int main()
{

    vector<int> nums = { 9,4,2,10,7,8,8,1,9 };
    maxTurbulenceSize(nums);

    return 0;
}